	package actions;

	import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

	import org.apache.struts.action.*;


	//import db.DbException;
	import forms.NameSubmitForm;
import model.Applicant;
import model.Database;

	public class NameSubmitAction extends Action {

		public ActionForward execute(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response){
					
			
			// Cast the form
			NameSubmitForm iForm = (NameSubmitForm) form;
			Applicant applicant = new Applicant();
			String username = request.getUserPrincipal().getName();
			
			//get and set userID
			try {
				applicant.setUserId(Database.getIdByUsername(username));
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			applicant.setName(iForm.getFirstName(), iForm.getMiddleInit(), iForm.getLastName());
			
			HttpSession session = request.getSession();
			session.setAttribute("applicant", applicant);

			return mapping.findForward("success");
		}
	}

	